package com.ruoyi.mng.controller;

import java.util.List;

import com.ruoyi.mng.domain.HzMerBalanceLog;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mng.domain.HzMerBalance;
import com.ruoyi.mng.service.IHzMerBalanceService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商户额度Controller
 * 
 * @author chenqiang
 * @date 2023-04-28
 */
@Controller
@RequestMapping("/mng/balance")
public class HzMerBalanceController extends BaseController
{
    private String prefix = "mng/balance";

    @Autowired
    private IHzMerBalanceService hzMerBalanceService;

    @RequiresPermissions("mng:balance:view")
    @GetMapping()
    public String balance()
    {
        return prefix + "/balance";
    }

    /**
     * 查询商户额度列表
     */
    @RequiresPermissions("mng:balance:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HzMerBalance hzMerBalance)
    {
        startPage();
        List<HzMerBalance> list = hzMerBalanceService.selectHzMerBalanceList(hzMerBalance);
        return getDataTable(list);
    }

    /**
     * 导出商户额度列表
     */
    @RequiresPermissions("mng:balance:export")
    @Log(title = "商户额度", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HzMerBalance hzMerBalance)
    {
        List<HzMerBalance> list = hzMerBalanceService.selectHzMerBalanceList(hzMerBalance);
        ExcelUtil<HzMerBalance> util = new ExcelUtil<HzMerBalance>(HzMerBalance.class);
        return util.exportExcel(list, "商户额度数据");
    }

    /**
     * 新增商户额度
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商户额度
     */
    @RequiresPermissions("mng:balance:add")
    @Log(title = "商户额度", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HzMerBalance hzMerBalance)
    {
        return toAjax(hzMerBalanceService.insertHzMerBalance(hzMerBalance));
    }

    /**
     * 修改商户额度
     */
    @RequiresPermissions("mng:balance:edit")
    @GetMapping("/edit/{balanceId}")
    public String edit(@PathVariable("balanceId") Long balanceId, ModelMap mmap)
    {
        HzMerBalance hzMerBalance = hzMerBalanceService.selectHzMerBalanceByBalanceId(balanceId);
        mmap.put("hzMerBalance", hzMerBalance);
        return prefix + "/edit";
    }

    /**
     * 修改保存商户额度
     */
    @RequiresPermissions("mng:balance:edit")
    @Log(title = "商户额度", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HzMerBalance hzMerBalance)
    {
        return toAjax(hzMerBalanceService.updateHzMerBalance(hzMerBalance));
    }

    /**
     * 删除商户额度
     */
    @RequiresPermissions("mng:balance:remove")
    @Log(title = "商户额度", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(hzMerBalanceService.deleteHzMerBalanceByBalanceIds(ids));
    }

    /**
     * 商户额度入账
     */
    @RequiresPermissions("mng:balance:edit")
    @Log(title = "商户额度", businessType = BusinessType.UPDATE)
    @PostMapping("/addBalance")
    @ResponseBody
    public AjaxResult addBalance(HzMerBalance hzMerBalance)
    {
        return toAjax(hzMerBalanceService.addBalance(hzMerBalance));
    }


    /**
     * 商户额度日志
     */
    @RequiresPermissions("mng:balance:edit")
    @GetMapping("/log/{balanceId}")
    public String log(@PathVariable("balanceId") Long balanceId, ModelMap mmap)
    {
        HzMerBalanceLog hzMerBalanceLog = new HzMerBalanceLog();
        hzMerBalanceLog.setBalanceId(balanceId);
        mmap.put("hzMerBalanceLog", hzMerBalanceLog);
        return prefix + "/balanceLog";
    }

}
